﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin.shop
{
    public partial class addwholesale : System.Web.UI.Page
    {
        // Fields

        // Methods
        private void Bind()
        {
            string sql = "select * from DB_memberank order by rankid asc";
            DataSet set = SQLAccess.GreatDs(sql);
            this.DataList1.DataSource = set;
            this.DataList1.DataBind();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["wid"] == null)
            {
                long num;
                string sql = "select * from DB_Wholesale order by wholesaleid desc";
                DataTable table = new DataTable();
                table = SQLAccess.GreatDs(sql).Tables[0];
                if (table.Rows.Count > 0)
                {
                    num = Convert.ToInt32(table.Rows[0]["wholesaleid"]) + 1;
                }
                else
                {
                    num = 1L;
                }
                string str2 = base.Request.Form["rankid"].ToString();
                SQLAccess.DoSql(string.Concat(new object[] { "insert into DB_Wholesale(wholesaleid,proid,rankid,visible) values(", num, ",", this.proname.SelectedValue, ",'", str2, "',", this.visible.Checked ? "1" : "0", ")" }));
                string[] strArray = base.Request.Form["text"].Split(new char[] { ',' });
                string[] strArray2 = base.Request.Form["text1"].Split(new char[] { ',' });
                for (int i = 0; i < strArray.Length; i++)
                {
                    if ((strArray[i].ToString() != "") && (strArray2[i].ToString() != ""))
                    {
                        SQLAccess.DoSql(string.Concat(new object[] { "insert into DB_sale(wholesaleid,proid,nums,prices) values(", num, ",", this.proname.SelectedValue, ",", strArray[i], ",", strArray2[i], ")" }));
                    }
                }
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            string sql = "select * from DB_Shoppro where visible=1";
            if (re.replace(this.keyname.Value) != null)
            {
                sql = sql + " and (proname like '%" + re.replace(this.keyname.Value) + "%' or procode like '%" + re.replace(this.keyname.Value) + "%')";
            }
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.proname.Items.Add(new ListItem(row["proname"].ToString(), row["proid"].ToString()));
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='../login.aspx';</script>");
                base.Response.End();
            }
            this.ImageButton1.Attributes["onclick"] = "return CheckFrm()";
            this.ImageButton1.Attributes["onclick"] = "return CheckSelect(true,'update');";
            if (!base.IsPostBack)
            {
                this.Bind();
                if (base.Request.QueryString["wid"] != null)
                {
                    this.upbind();
                }
            }
        }

        private void upbind()
        {
            DataSet set = SQLAccess.GreatDs("select * from DB_sale where wholesaleid=" + base.Request.QueryString["wid"].ToString() + "");
            this.DataList2.DataSource = set;
            this.DataList2.DataBind();
            string sql = "select * from DB_Wholesale where wholesaleid=" + base.Request.QueryString["wid"].ToString() + "";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                string str3 = "select * from DB_Shoppro where proid=" + table.Rows[0]["proid"].ToString() + "";
                DataTable table2 = new DataTable();
                table2 = SQLAccess.GreatDs(str3).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    this.proname.Items.Add(new ListItem(table2.Rows[0]["proname"].ToString(), table2.Rows[0]["proid"].ToString()));
                }
            }
        }

 

    }
}